﻿@model dsacbasic.Models.ListOrdersInfo
@{
    ViewBag.Title = "订单管理";
}
<div style="height: 40px; line-height: 40px; padding: 0 10px;">
    <div class="pull-right" style="height: 40px; line-height: 40px;">
        <a href='@Url.Action("Excel", new { cate = Request.QueryString["cate"], keyword = Request.QueryString["keyword"] })' target="_blank" class="btn  btn-primary btn-large">
            <i class="icon-list icon-white"></i>导出Excel</a>
    </div>
    <div style="height: 40px; line-height: 40px;">
        <h2 id="bigTitle">
            @ViewBag.Title
        </h2>
    </div>
</div>
<hr />
<div class="row" style="margin-top: 20px;">
    <div class="searchBar">
        订单状态：<select id="searchCate">
            <option value="-100"></option>
            @{foreach (var cate in Model.Search.Cates)
              {
                  if (Model.Search.CurrentCate == cate.ID)
                  {
                <option selected="selected" value="@cate.ID">@cate.Name</option>
                  }
                  else
                  {
                <option value="@cate.ID">@cate.Name</option>
                  }
              }
            }
        </select>
        订单编号：<input type="text" id="searchText" value="@Model.Search.Keyword" />
        <input type="button" id="searchBtn" value="搜索" />
    </div>
</div>
@Html.Partial("MessageTip")
<table class="table table-bordered">
    <thead>
        <tr>
            <th>
                订单编号
            </th>
            <th>
                收货人
            </th>
            <th>
                订单金额
            </th>
            <th>
                下单时间
            </th>
            <th>
                订单类型
            </th>
            <th>
                订单状态
            </th>
            <th>
                操作
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (GADC.Domain.Orders obj in Model.List)
        {
            <tr>
                <td>
                    @obj.OrderID
                </td>
                <td>
                    @obj.ReceiveName
                </td>
                <td>
                    @obj.Price
                </td>
                <td>
                    @(obj.Time != null ? obj.Time.ToString("yyyy-MM-dd HH:mm:ss") : "")
                </td>
                <td>
                    @obj.OrderType.Name
                </td>
                <td>
                    @obj.OrderStatus.Name
                </td>
                <td>
                    @if (obj.OrderType.ID == 0)
                    {
                        <a class="operate" href="#">查看</a>
                    }
                    else
                    {
                        <a class="operate" href="@Url.Action("Detail", new {id=obj.ID})">查看</a>
                    }
                    @switch (obj.OrderStatus.ID)
                    {
                        case 0:
                        <a class="operate" href="javascript:EditPrice(@obj.ID,'@obj.OrderID','@obj.Price')">
                            改价</a>
                        <a class="operate" href="javascript:acceptOrder(@obj.ID)">通过</a>
                        <a class="operate" href="javascript:rejectOrder(@obj.ID)">拒绝</a>
                                                                   break;
                        case 1:
                        <a class="operate" href="javascript:EditPrice(@obj.ID,'@obj.OrderID','@obj.Price')">
                            改价</a>
                                                                                          break;
                        case 2: break;
                        case 3:
                        <a class="operate" href="javascript:shipOrder(@obj.ID)">货已发</a>
                                                                 break;
                        case 4:
                        <a class="operate" href="javascript:endOrder(@obj.ID)">结束订单</a>
                                                                break;
                        case 5: break;
                    }
                </td>
            </tr>
        }
    </tbody>
</table>
@Html.Partial("Pager", Model.Pager, new ViewDataDictionary() { { "Keyword", Model.Search.Keyword }, { "CurrentCate", Model.Search.CurrentCate } })
<form id="hideForm" action='@Url.Action("Operate")' method="post">
<input type="hidden" id="Status" name="Status" />
<input type="hidden" id="ID" name="ID" />
</form>
<div class="modal hide fade" id="addOne-modal" data-backdrop="static" data-keyboard="false">
    <form id="cateForm" action='@Url.Action("EditPrice")' method="post">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3 id="myModalLabel">
           改价</h3>
    </div>
    <br />
    <fieldset>
        <div class="span5">
            <input type="hidden" name="OID" id="OID" />
            订单编号：<input type="text" disabled="disabled" name="OrderID" id="OrderID" />
            <br />
            修改价格：<input type="text" name="Price" id="Price" />
        </div>
        <div class="span1 offset2">
            <input type="submit" id="recipe-btn" value="保 存" class="btn btn-blue span1" />
        </div>
    </fieldset>
    </form>
</div>
@section scripts{
    @Html.Partial("SearchScript", Model.Search)
    <script type="text/javascript">
        function Operating(status, id) {
            $("#Status").val(status);
            $("#ID").val(id);
            $("#hideForm").submit();
        }


        function acceptOrder(id) {
            if (window.confirm("确定审核通过该订单申请?")) {
                Operating(1, id);
            }
        }

        function rejectOrder(id) {
            if (window.confirm("确定审核拒绝该订单申请?")) {
                Operating(2, id);

            }
        }

        function shipOrder(id) {
            if (window.confirm("确定将该订单状态改为'已发货'?")) {
                Operating(4, id);
            }
        }

        function endOrder(id) {
            if (window.confirm("确定将该订单状态改为'已结束'?")) {
                Operating(5, id);
            }
        }


        function EditPrice(id,oid, price) {
            $("#OID").val(id);
            $("#OrderID").val(oid);
            $("#Price").val(price);
            $('#addOne-modal').modal('show');
        }
    </script>
}
